package org.mokusakura.web.controller;

import org.mokusakura.constant.ServletUrlConstant;
import org.mokusakura.service.CatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SearchController {
    public static final String KEY_WORD_TO_SEARCH = "keyword";
    @Autowired
    private CatalogService catalogService;

    @GetMapping(ServletUrlConstant.SEARCH_SERVLET_URL)
    protected Object quickSearch(@RequestParam(KEY_WORD_TO_SEARCH) String keyword) {
        /* TODO Due to the limited time, each request will access to the database.
         *  This must be optimize to decrease the pressure of database.*/
        return catalogService.searchProductByKeyword(keyword);
    }
}
